package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.resource.entity.QueryPageBean;
import com.itheima.health.service.CheckItemService;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
@Transactional
public class CheckItemServiceImpl extends ServiceImpl<CheckItemMapper, CheckItem> implements CheckItemService {
    @Override
    public Map findPageByContion(QueryPageBean queryPageBean) {
        // 条件构造器
        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<CheckItem>();
        String queryString = queryPageBean.getQueryString();//  条件
        queryWrapper.like("name",queryString==null?"":queryString);
        queryWrapper.eq("is_delete",0);//  有效数据
//        LambdaQueryWrapper<CheckItem> lambda = new QueryWrapper<CheckItem>().lambda();
//        lambda.like(CheckItem::getName,"tps").or().eq(CheckItem::getAge,10);
        //  select  * from xxx where name like  xx  and  is_delete = 0
        //  分页请求参数条件
        Page<CheckItem> pageResult = page(new Page<CheckItem>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()), queryWrapper);
        List<CheckItem> checkItemList = pageResult.getRecords();
        long total = pageResult.getTotal();
        Map map = new HashMap(); //  定义一个Map对象 封装分页查询结果集数据
        map.put("list",checkItemList);  //  分页数据
        map.put("total",total);  // 总记录数
        return map;
    }

    @Override
    public List<CheckItem> findAll() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_delete",0);//  有效数据
        List<CheckItem> list = list(queryWrapper);
        return list;
    }

    @Override
    public List<Integer> findCheckItemIdsByGroupId(int id) {
        return baseMapper.findCheckItemIdsByGroupId(id);
    }

//    @Override // sql
//    public Map findPageByContion(QueryPageBean queryPageBean) {
//       List<CheckItem> checkItemList = baseMapper.findPageByContion(queryPageBean);
//       long total = baseMapper.findCountsByContion(queryPageBean);
//
//        Map map = new HashMap(); //  定义一个Map对象 封装分页查询结果集数据
//        map.put("list",checkItemList);  //  分页数据
//        map.put("total",total);  // 总记录数
//        return map;
//    }

}
